<?php
//
//  VictoryCMS - Content managment system and framework.
//  Copyright (C) 2009  Lewis Gunsch
//
//  This file is part of VictoryCMS.
//  
//  VictoryCMS is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  VictoryCMS is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with VictoryCMS.  If not, see <http://www.gnu.org/licenses/>.

/**
 * VictoryCMS - Table
 * 
 * @license http://www.gnu.org/licenses/gpl.html
 * @author Lewis Gunsch
 * @filesource
 * @package HtmlBuilders
 */

/**
 * @package HtmlBuilders
 * 
 * @todo Finish documenting and implementing Table XHTML tags
 */
class Table extends HtmlBuilder {

	public function __construct(HtmlList &$list) {
		parent::__construct($list);
	}

	public function __destruct() {
		parent::__destruct();
	}

	public function beginTable(Array $attributes) {
		$html = '<table ';
		if (!empty($attributes['id'])) {
			$html .= ' id="'.$attributes['id'].'"';
		}
		if (!empty($attributes['cellpadding'])) {
			$html .= ' cellpadding="'.$attributes['cellpadding'].'"';
		}
		if (!empty($attributes['cellspacing'])) {
			$html .= ' cellspacing="'.$attributes['cellspacing'].'"';
		}
		if (!empty($attributes['width'])) {
			$html .= ' width="'.$attributes['width'].'"';
		}
		if (!empty($attributes['border'])) {
			$html .= ' border="'.$attributes['border'].'"';
		}
		if (!empty($attributes['title'])) {
			$html .= ' title="'.$attributes['title'].'"';
		}
		if (!empty($attributes['class'])) {
			$html .= ' class="'.$attributes['class'].'"';
		}
		if (!empty($attributes['style'])) {
			$html .= ' style="'.$attributes['style'].'"';
		}
		$html .= '>';
		$this->list->add($html);
	}

	public function endTable() {
		$this->list->add('</table>');
	}

	public function beginRow(Array $attributes) {
		$html = '<tr ';
		if (!empty($attributes['id'])) {
			$html .= ' id="'.$attributes['id'].'"';
		}
		if (!empty($attributes['align'])) {
			$html .= ' align="'.$attributes['align'].'"';
		}
		if (!empty($attributes['valign'])) {
			$html .= ' valign="'.$attributes['valign'].'"';
		}
		if (!empty($attributes['width'])) {
			$html .= ' width="'.$attributes['width'].'"';
		}
		if (!empty($attributes['title'])) {
			$html .= ' title="'.$attributes['title'].'"';
		}
		if (!empty($attributes['class'])) {
			$html .= ' class="'.$attributes['class'].'"';
		}
		if (!empty($attributes['style'])) {
			$html .= ' style="'.$attributes['style'].'"';
		}
		$html .= '>';
		$this->list->add($html);
	}

	public function endRow() {
		$this->list->add('</tr>');
	}

	public function pushCell($data, Array $attributes) {
		$html = '<td ';
		if (!empty($attributes['id'])) {
			$html .= ' id="'.$attributes['id'].'"';
		}
		if (!empty($attributes['rowspan'])) {
			$html .= ' rowspan="'.$attributes['rowspan'].'"';
		}
		if (!empty($attributes['colspan'])) {
			$html .= ' colspan="'.$attributes['colspan'].'"';
		}
		if (!empty($attributes['align'])) {
			$html .= ' align="'.$attributes['align'].'"';
		}
		if (!empty($attributes['valign'])) {
			$html .= ' valign="'.$attributes['valign'].'"';
		}
		if (!empty($attributes['title'])) {
			$html .= ' title="'.$attributes['title'].'"';
		}
		if (!empty($attributes['class'])) {
			$html .= ' class="'.$attributes['class'].'"';
		}
		if (!empty($attributes['style'])) {
			$html .= ' style="'.$attributes['style'].'"';
		}
		$html .= '>'.$data.'</td>';
		$this->list->add($html);
	}
	
	public function pushTableHeadCell($data, Array $attributes) {
		$html = '<th ';
		if (!empty($attributes['id'])) {
			$html .= ' id="'.$attributes['id'].'"';
		}
		if (!empty($attributes['rowspan'])) {
			$html .= ' rowspan="'.$attributes['rowspan'].'"';
		}
		if (!empty($attributes['colspan'])) {
			$html .= ' colspan="'.$attributes['colspan'].'"';
		}
		if (!empty($attributes['align'])) {
			$html .= ' align="'.$attributes['align'].'"';
		}
		if (!empty($attributes['valign'])) {
			$html .= ' valign="'.$attributes['valign'].'"';
		}
		if (!empty($attributes['title'])) {
			$html .= ' title="'.$attributes['title'].'"';
		}
		if (!empty($attributes['class'])) {
			$html .= ' class="'.$attributes['class'].'"';
		}
		if (!empty($attributes['style'])) {
			$html .= ' style="'.$attributes['style'].'"';
		}
		$html .= '>'.$data.'</th>';
		$this->list->add($html);
	}
}
?>
